package com.me.chat.controller.bis.user;

import com.me.chat.pojo.suport.ResultBean;
import com.me.chat.pojo.user.UserInfo;
import com.me.chat.pojo.user.qo.UserInfoQO;
import com.me.chat.pojo.user.vo.UserDetailInfoVO;
import com.me.chat.service.user.UserService;
import com.me.chat.util.stauts.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Authhor: qiu
 * @Date: 2021/11/13 5:08 下午
 */
@RestController
@RequestMapping("/res/user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 获取当前登录用户的信息
     * @return
     */
    @GetMapping("/get_userinfo")
    public ResultBean<UserInfo> getUserInfo() {
        UserInfo userInfo = userService.getUserInfo();
        return new ResultBean<>(StatusCode.SUCCEED,userInfo,"用户信息获取成功");
    }

    /**
     * 根据用户id 获取指定用户
     * @param userId
     * @return
     */
    @GetMapping("/get_userinfo_by_id")
    public ResultBean<UserInfo> getUserInfo(String userId) {
        UserInfo userInfo = userService.getUserInfo(userId);
        return new ResultBean<>(StatusCode.SUCCEED,userInfo,"用户信息获取成功");
    }

    /**
     * 获取更加详细的用户信息
     * @param userId
     * @return
     */
    @GetMapping("/get_user_detail_by_id")
    public ResultBean<UserDetailInfoVO> getUserDetailInfo(String userId) {
        if(userId == null || userId.length() == 0) {
            return new ResultBean<>(StatusCode.ERROR,null,"用户id不能为空");
        }
        UserDetailInfoVO userDetailInfo = userService.getUserDetailInfo(userId);
        return new ResultBean<>(StatusCode.SUCCEED,userDetailInfo,"用户详细信息获取成功");
    }



    /**
     * 根据userName 与 showName 来搜索用户 带分页参数
     * @param userInfoQO
     * @return
     */
    @GetMapping("/search_user")
    public ResultBean<List<UserInfo>> searchUser(UserInfoQO userInfoQO) {
        List<UserInfo> userInfos = userService.searchUser(userInfoQO);
        String searchVal = userInfoQO.getSearchVal();
        if("".equals(searchVal) || searchVal == null) {
           return new ResultBean<>(StatusCode.ERROR,null,"搜索值不能为空");
        }
        return new ResultBean<>(StatusCode.SUCCEED,userInfos,"用户搜索成功");
    }
}
